package com.myjoje.controller.system;

import com.myjoje.base.BaseController;
import com.myjoje.bean.system.DeptBean;
import com.myjoje.service.system.DeptService;
import com.myjoje.util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门管理
 */
@RestController
@RequestMapping("/system/dept")
public class DeptController extends BaseController {

    @Autowired
    private DeptService deptService;

    /**
     * 保存或更新部门
     */
    @RequestMapping("/saveOrUpdateDept")
    public Object saveOrUpdateDept(DeptBean bean, String userIds) {
        return deptService.saveOrUpdateDept(bean, userIds);
    }

    /**
     * 部门分页数据
     */
    @RequestMapping("/getDeptPagingData")
    public Object getDeptPagingData(Integer currentPage, Integer pageSize) {
        List<DeptBean> rows = deptService.getDeptList(currentPage, pageSize);
        Long count = deptService.getDeptCount();
        return Message.success("获取成功", getPagingData(rows, count));
    }

    /**
     * 删除部门
     */
    @RequestMapping("/deleteDept")
    public Object deleteDept(String id) {
        return deptService.deleteDept(id);
    }

    /**
     * 删除部门
     */
    @RequestMapping("/getDeptById")
    public Object getDeptById(String id) {
        return deptService.getDeptById(id);
    }

    /**
     * 获取所有部门
     */
    @RequestMapping("/getAllDept")
    public Object getAllDept() {
        return deptService.getAllDept();
    }

}
